/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019.
 * Description: file monitor use old uesr interface
 * Author: panlong
 * Create: 2018-11-13
 */

#include <linux/spinlock.h>
#include <linux/fsnotify_backend.h>

#include "inotify.h"

DEFINE_MUTEX(g_fm_kernel_mutex);
static const struct fsnotify_group *g_fm_group;
rtos_fm_handler_func g_fm_handler;
bool set_fm_group_and_handler(const struct fsnotify_group *group, rtos_fm_handler_func handler)
{
	mutex_lock(&g_fm_kernel_mutex);
	if (g_fm_group && group) {
		mutex_unlock(&g_fm_kernel_mutex);
		return false;
	}

	g_fm_group = group;
	g_fm_handler = handler;
	mutex_unlock(&g_fm_kernel_mutex);
	return true;
}

bool compare_to_fm_group(const struct fsnotify_group *in)
{
	bool ret = false;
	mutex_lock(&g_fm_kernel_mutex);
	ret = (in == g_fm_group);
	mutex_unlock(&g_fm_kernel_mutex);

	return ret;
}

void destroy_inotify_group(struct fsnotify_group *group)
{
	if (group)
		fsnotify_destroy_group(group);
	set_fm_group_and_handler(NULL, NULL);
}
EXPORT_SYMBOL_NS(destroy_inotify_group, RTOS_DEBUG_RSM);
